package com.fh.shop.api.book.controller;

import com.fh.shop.api.book.biz.IBookService;
import com.fh.shop.api.book.param.BookQueryParam;
import com.fh.shop.api.book.po.Book;
import com.fh.shop.api.common.DataTableResult;
import com.fh.shop.api.common.ServerResponse;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RequestMapping("/api/book")
@RestController
@CrossOrigin
public class BookController {

    @Resource(name = "bookService")
    private IBookService bookService;

    @RequestMapping(value ="/add", method = RequestMethod.POST)
    public ServerResponse add(Book book) {
        return bookService.addBook(book);
    }

    @RequestMapping(value ="/list", method = RequestMethod.POST)
    public ServerResponse list() {
        return bookService.findList();
    }

    @RequestMapping(value ="/delete", method = RequestMethod.POST)
    public ServerResponse delete(Long id) {
        return bookService.deleteBook(id);
    }

    @RequestMapping(value ="/deleteBatch", method = RequestMethod.POST)
    public ServerResponse deleteBatch(String ids) {
        return bookService.deleteBatch(ids);
    }

    @RequestMapping(value ="/find", method = RequestMethod.GET)
    public ServerResponse find(Long id) {
        return bookService.findBook(id);
    }

    @RequestMapping(value ="/update", method = RequestMethod.POST)
    public ServerResponse update(Book book) {
        return bookService.updateBook(book);
    }

    @RequestMapping(value ="/findList", method = RequestMethod.POST)
    public DataTableResult findList(BookQueryParam bookQueryParam) {
        return bookService.findPageList(bookQueryParam);
    }







}
